feat(CFG): Verified implementation of Kildall's algorithm - #782
feat(CFG): Verified implementation of Kildall's algorithm#782quartztz wants to merge 10 commits into
Conversation
| * [G. Kildall, *A Unified Approach to Global Program Optimization*][Kildall73] | ||
| * [F. Nielson, H.R. Nielson, C. Hankin, *Principles of Program Analysis*][Nielson99] | ||
| * [R. LaSpina, *Formal Verification of WTO-based Dataflow Solvers*][LaSpina25] |
There was a problem hiding this comment.
Please add these references to the file references.bib.
| /-- Abstract structure defining the necessary operations on a CFG to define a Control Flow Graph. -/ | ||
| class CFG (Node Edge : Type) [DecidableEq Node] [DecidableEq Edge] where | ||
| /-- All of the nodes in the CFG. -/ | ||
| nodes : List Node | ||
| /-- All of the edges in the CFG. -/ | ||
| edges : List Edge | ||
| /-- A distinguished entry node in the CFG. -/ | ||
| entry : Node | ||
| /-- A proof that the entry node is part of the graph's nodes. -/ | ||
| entry_mem : entry ∈ nodes | ||
| /-- Extractor function for an edge's source node. -/ | ||
| _srcOf : Edge → Node | ||
| /-- Proof of correctness for the source extractor. -/ | ||
| srcOf_mem : ∀ e ∈ edges, _srcOf e ∈ nodes | ||
| /-- Extractor function for an edge's destination node. -/ | ||
| _dstOf : Edge → Node | ||
| /-- Proof of correctness for the destination extractor. -/ | ||
| dstOf_mem : ∀ e ∈ edges, _dstOf e ∈ nodes |
There was a problem hiding this comment.
I have some questions about the design of CFG:
- Normally the nodes and edges of a graph are taken to be sets (which can be modeled by
SetorFinset). Why do you define them to be lists and then build types from them (NodeOfandEdgeOf)? Scanning the code inKildall.lean, I'm not sure you ever used the fact thatnodesandedgesare lists (rather than sets). - For that matter, do you really need the generality that
nodesandedgesare subsets ofNodeandEdge. Can they simply be the whole types? Then you won't need constraints likesetOf_memanddstOf_mem. - There is something called
Quiverin mathlib:
https://leanprover-community.github.io/mathlib4_docs/Mathlib/Combinatorics/Quiver/Basic.html
Would it usable for your purpose? - Why did you put
_at the beginning of_srcOfanddstOf?
There was a problem hiding this comment.
I agree with the fact that the current presentation is very roundabout. I did not know about Quiver, but I feel like applying it would fix these comments: using a single type for Nodes and a quiver to characterize the edges would both remove unneeded fields and make the projections easier.
The _ was a crude way to mark that field as "internal", since the preferred API (that returns a NodeOf g) is defined in terms of it. However, this problem disappears when applying the other changes, so i'll draft a new structure to hopefully fix everything in one go.
Thank you for your comments and for the pointer!
|
Second try, integrating the previous comments regarding the type of While the definition of the CFG using My question is therefore the following: what's the project's stance on computability? I'm not a huge fan of this workaround, but I cannot see a way to make computability work without it. I having a noncomputable algorithm is a shame, but that means that either the If the library doesn't care about the algorithm being computable, then the |
ctchou
left a comment
There was a problem hiding this comment.
Your patch produced a very large diff on references.bib which obscures the change you actually made. Could you revert it and make your small change manually? We are not against reformatting references.bib, but that should be done in a separate PR and not be mixed with this PR.
|
That's my bad, the autoformatter kicked in. Pushed a commit to fix! Sorry about that. |
As discussed on Zulip, here is an implementation of Kildall's worklist algorithm for solving dataflow equations. The design features a small CFG api, as well as a characterization of correctness in terms of different flavors of fixpoints. Three main theorems show that
Definitions of the structures are in
Analysis/Dataflow/CFG.lean, and the algorithm and proofs are inAnalysis/Dataflow/Kildall.lean. I didn't feel like it fit semantically in any other directory, but I'll be glad to move it if there's better.TODO: fix all lints :(